<?php
/**
 * Created by IntelliJ IDEA.
 * User: keke
 * Date: 18-10-26
 * Time: 下午4:20
 */
require_once "../lib/common.php";
require_once "../congfig/config.php";
$username = $_POST['username'];
$passwd = enpasswd($_POST['passwd']);
$veriypasswd = enpasswd($_POST['veriypasswd']);
$email = $_POST['email'];
@$rank = $_POST['rank'];
$realname = $_POST['realname'];
if ($username == null || $passwd == null || $email == null) {
    exit(jsoncall(-1, "信息不能为空"));
}
if(!is_numeric($username))
{
    exit(jsoncall(-1,"请输入学号"));
}
if ($passwd !== $veriypasswd) {
    exit(jsoncall(-1, "两次密码不一致"));
}
$sql = "select * from users where username = '$username'";
$query = $conn->query($sql);
$num = $query->num_rows;
if ($num >= 1) {
    exit(jsoncall(-1, "已存在该用户"));
}
$sql = "select * from userinfor where realname = '$realname'";
$query = $conn->query($sql);
$num = $query->num_rows;
if ($num >= 1) {
    exit(jsoncall(-1, "已存在该实名用户"));
}
if ($query) {
    $sql = "insert into users values (null,'$username','$passwd','$email','$rank')";
    $query = $conn->query($sql);
    $sql="select * from users where username = '$username'";
    $query=$conn->query($sql);
    $result = $query->fetch_array();
    $uid = $result['uid'];
    $sql = "insert into userinfor values (null,'$uid','$realname' ,null ,null )";
    $query=$conn->query($sql);
    $sql = "select * from userinfor where realname = '$realname'";
    $query=$conn->query($sql);
    if ($query) {
        exit(jsoncall(1, "添加信息成功"));
    } else {
        exit(jsoncall(-1, "添加信息失败"));
    }

} else {
    exit(jsoncall(-1, "添加失败"));
}


